#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <time.h>
#include <iostream>
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>

#include "argvparser.h"
#include "ComputationDisk.h"
#include "fillArgument.h"

using namespace std;
using namespace CommandLineProcessing;

int main(int argc, char* argv[]){
  
  // environement
  Environment * env = new Environment();
  ComputationDisk *CDisk = NULL;

  // parser for argument. 
  ArgvParser parser; 
  fillArguments(&parser);

  // parse and handle return codes (display help etc...)
  int result = parser.parse(argc, argv);
  if (result != ArgvParser::NoParserError){
    cout << parser.parseErrorDescription(result);
    exit(1);
  }

  // use parser to create the tests environment
  // define size 
  if(parser.foundOption("s")) {
    env->setBlockSize(parser.optionValue("s")); 
  }else {
    env->setBlockSize(B); 
  }

  // define thread
  if(parser.foundOption("t")){
    env->setThread(parser.optionValue("t"));
  }else {
    env->setThread("2");
  }

  // define access 
  if (parser.foundOption("a")){
    env->setAccess(parser.optionValue("a"));
  }else {
    env->setAccess(0);
  }  

  // define method 
  if (parser.foundOption("m")){
    env->setMethod(parser.optionValue("m"));
  }else {
    env->setMethod(0);
  }  


  CDisk = new ComputationDisk(env);

  //intitialize the random in case of random access
  srand(time(NULL));

  CDisk->runTests();
 
  return EXIT_SUCCESS;
}
